package com.d3works.apps.base.db.repo;

import com.d3works.apps.base.db.Address;
import com.d3works.apps.base.service.AddressService;
import com.d3works.exception.service.TraceBackService;
import com.google.inject.Inject;
import javax.persistence.PersistenceException;

public class AddressBaseRepository extends AddressRepository {

  @Inject protected AddressService addressService;

  @Override
  public Address save(Address entity) {

    entity.setFullName(addressService.computeFullName(entity));
    try {
      addressService.updateLatLong(entity);
    } catch (Exception e) {
      TraceBackService.traceExceptionFromSaveMethod(e);
      throw new PersistenceException(e.getMessage(), e);
    }

    return super.save(entity);
  }
}
